package com.jsp.web; /**
 * @author wzm
 * @create 2023-05-05 9:38
 */

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/rs1")
public class ResponseServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //当访问该servlet时向客户端响应一个网页
        response.setContentType("text/html;charset=UTF-8");


//        PrintWriter writer = response.getWriter();
//
//        writer.write("<!DOCTYPE html>");
//        writer.write("<html lang=\"en\">");
//        writer.write("<head>");
//        writer.write(" <meta charset=\"UTF-8\">");
//        writer.write("<title>Document</title>");
//        writer.write("</head>");
//        writer.write("<body>");
//        writer.write("<!DOCTYPE html>");
//        writer.write("<h1>HelloWorld</h1>");
//        writer.write("</body>");
//        writer.write("</html>");

        //使用jsp显示数据
        request.getRequestDispatcher("/hello.jsp").forward(request,response);


    }
}
